package com.foreknow.springboot.controller;

import com.foreknow.springboot.po.DeliveryAddress;
import com.foreknow.springboot.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/13 19:51
 * @function:
 */
@RestController
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {
    //注入依赖
    @Autowired
    private DeliveryAddressService deliveryAddressService;

    //http://localhost:8089/elm/DeliveryAddressController/listDeliveryAddressByUserId?userId=12345671111
    @RequestMapping("/listDeliveryAddressByUserId")
    List<DeliveryAddress> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress){
       return deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId());
    }

    //http://localhost:8089/elm/DeliveryAddressController/getDeliveryAddressById?daId=2
    @RequestMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
    }

    //http://localhost:8089/elm/DeliveryAddressController/saveDeliveryAddress?contactName=abc&contactSex=1&contactTel=neymar&address=aaa&userId=123456
    @RequestMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.saveDeliveryAddress(deliveryAddress.getContactName(),deliveryAddress.getContactSex(),deliveryAddress.getContactTel(),deliveryAddress.getAddress(),deliveryAddress.getUserId());
    }
    //http://localhost:8089/elm/DeliveryAddressController/updateDeliveryAddress?daId=24&contactName=12121&contactSex=1&contactTel=1222222&address=ttt&userId=666
    @RequestMapping("/updateDeliveryAddress")
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.updateDeliveryAddress(deliveryAddress.getDaId(),deliveryAddress.getContactName(),deliveryAddress.getContactSex(),deliveryAddress.getContactTel(),deliveryAddress.getAddress(),deliveryAddress.getUserId());
    }
    //http://localhost:8089/elm/DeliveryAddressController/removeDeliveryAddress?daId=24
    @RequestMapping("/removeDeliveryAddress")
    public int removeDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
    }


}
